package com.bestcem.xm.user.util.business;

import com.bestcem.xm.user.service.dto.user.OrgCustomSettingInfoDTO;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

/**
 * 租户自定义配置信息线程本地变量工具类
 *
 * @author qiongyu.cui <qiongyu.cui@idiaoyan.com>
 * @version v1.0
 * @date 2022/6/15 18:27
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class CustomSettingThreadLocalUtil {

    private static final ThreadLocal<OrgCustomSettingInfoDTO> THREAD_LOCAL = new ThreadLocal<>();

    /**
     * 添加setting配置到threadLocal中
     *
     * @param customSettingInfoDTO 租户自定义配置信息
     * @author cuiqiongyu <qiongyu.cui@idiaoyan.cn>
     * @date 2022/06/15 18:41
     */
    public static void setCustomSetting(OrgCustomSettingInfoDTO customSettingInfoDTO) {
        THREAD_LOCAL.set(customSettingInfoDTO);
    }

    /**
     * 从threadLocal中获取setting配置
     *
     * @return com.bestcem.xm.user.service.dto.user.OrgCustomSettingInfoDTO
     * @author cuiqiongyu <qiongyu.cui@idiaoyan.cn>
     * @date 2022/06/15 18:41
     */
    public static OrgCustomSettingInfoDTO getCustomSetting() {
        return THREAD_LOCAL.get();
    }

    /**
     * 删除当前 setting配置
     */
    public static void removeCustomSetting() {
        THREAD_LOCAL.remove();
    }

}
